package org.zk.dubbo_consumer.utils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.live.model.v20161101.AddLiveStreamTranscodeRequest;
import com.aliyuncs.live.model.v20161101.AddLiveStreamTranscodeResponse;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @ClassName: AddLiveStreamTranscodeUtil
 * @Description: 工具类：通过调用阿里云的API,为每个主播配置转码模版
 * @Author: 刘艺广
 * @Date: 2019/12/24 0024 下午 4:39
 **/
public class AddLiveStreamTranscodeUtil {
    /**
     * 地域：华南1（深圳）
     */
    private static final String regionId = "cn-shenzhen";

    /**
     * accessKeyId: 如果要调用阿里云的API，必须要有accessKey，包括accessKeyId和accessKeySecret
     */
    private static final String accessKeyId = "LTAI4FfnAUbV5gLVAoq2uvJ4";

    /**
     * accessKeySecret
     */
    private static final String accessKeySecret = "hGLmVgqZbGV2dWI4r6xtL804Tj2AhD";

    /**
     * 域名
     */
    private static final String Domain = "pull.alicelonely.com";

    /**
     * 此处为阿里云代码示例的内容，要调用阿里云的API
     */
    private static DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
    private static IAcsClient client = new DefaultAcsClient(profile);
    private static AddLiveStreamTranscodeRequest request = new AddLiveStreamTranscodeRequest();


    /**
     * @MethodName: addTranscode
     * @Description: 调用三个方法，分别配置标清、高清、超清转码模版
     * @Param: [appName]
     * @Return: void
     * @Author: 刘艺广
     * @Time: 2019/12/24 0024 下午 7:53
     **/
    public static void addTranscode(String appName){
        addTranscodeSD(appName);
        addTranscodeHD();
        addTranscodeUD();
    }

    /**
     * 配置标清模版
     * @param appName
     */
    public static void addTranscodeSD(String appName){

        request.setTemplate("sd");
        request.setDomain(Domain);
        request.setRegionId(regionId);
        request.setApp(appName);
        try {
            AddLiveStreamTranscodeResponse response = client.getAcsResponse(request);
        }  catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }

    /**
     * 配置高清模版
     * @param
     */
    public static void addTranscodeHD(){
        request.setTemplate("hd");
        try {
            AddLiveStreamTranscodeResponse response = client.getAcsResponse(request);
        }  catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }

    /**
     * 配置超清模版
     * @param
     */
    public static void addTranscodeUD(){
        request.setTemplate("ud");
        try {
            AddLiveStreamTranscodeResponse response = client.getAcsResponse(request);
        }  catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }
}
